package com.vanke.kotlin.db

import com.vanke.kotlin.domain.Forecast
import com.vanke.kotlin.domain.ForecastList

/**
 * @name Kotlin
 * @package name：com.vanke.kotlin.db
 * @class describe
 * @anthor shiyuchuan
 * @time 2017/7/25 14:19
 */
class DbDataMapper{

    fun convertToDomain(forecast: CityForecast) = with(forecast){
        val daily = dailyForecast.map { convertDayToDomain(it) }
        ForecastList(_id,city,country,daily)
    }

    fun  convertDayToDomain(dayForecast: DayForecast) = with(dayForecast){
     Forecast(_id,date,description,high,low,iconUrl)
    }

    fun convertFromDomain(forecast: ForecastList) = with(forecast){
        val daily = dailyForecast.map { convertDayFromDomain(id,it)}
        CityForecast(id,city,country,daily)
    }

    private fun  convertDayFromDomain(id: Long,forecast: Forecast) = with(forecast){
        DayForecast(date = date,description = description,high = high,
                low = low,iconUrl = iconUrl,cityId = id)
    }
}